package com.example.weli.ble2test;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
import android.graphics.Paint.Align;
import android.graphics.Typeface;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy.Builder;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.weli.ble2test.MyDialogListener;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Random;
import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

public class UIActivity extends AppCompatActivity implements MyDialogListener, OnTouchListener {
    Gson mGson;
    NewBean newBean;

    private static final boolean D = true;
    public static final String DEVICE_NAME = "device_name";
    static final char[] HEX_CHAR_TABLE = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    public static final byte LED_SERVO_COMMAND = (byte) 2;
    public static final int MESSAGE_DEVICE_NAME = 4;
    public static final int MESSAGE_READ = 2;
    public static final int MESSAGE_STATE_CHANGE = 1;
    public static final int MESSAGE_TOAST = 5;
    public static final int MESSAGE_WRITE = 3;
    public static final int Mode_Com = 1;
    public static final int Mode_Serv = 4;
    public static final int Mode_Sta = 2;
    public static final int Mode_Ubd = 3;
    public static final int Mode_tcp = 5;
    public static final int PWM_Offset = 1500;
    private static final int REQUEST_CONNECT_DEVICE = 1;
    private static final int REQUEST_Connect_TCP = 3;
    private static final int REQUEST_ENABLE_BT = 2;
    static int RX_Count = 0;
    private static final String TAG = "Bluetooth Com";
    public static final int TCP_CHANGE = 7;
    public static final int TCP_READ = 6;
    public static final String TOAST = "toast";
    static int TX_Count = 0;
    public static final int idle = 5;
    public static final int xconnected = 2;
    public static final int xend = 4;
    public static final int xtransfing = 3;
    public static final int xtryconnet = 1;
    boolean B10_viable;
    boolean B11_viable;
    boolean B12_viable;
    boolean B1_viable;
    boolean B2_viable;
    boolean B3_viable;
    boolean B4_viable;
    boolean B5_viable;
    boolean B6_viable;
    boolean B7_viable;
    boolean B8_viable;
    boolean B9_viable;
    int BL_Mode = xtryconnet;
    String Checkoff = "Check OFF";
    String Checkon = "Check ON";
    private EditText Edit1;
    CheckBox HEX_EN;
    String LED1_name;
    boolean LED1_viable;
    String LED2_name;
    boolean LED2_viable;
    String LED3_name;
    boolean LED3_viable;
    String LED4_name;
    boolean LED4_viable;
    String LED5_name;
    boolean LED5_viable;
    String LED6_name;
    boolean LED6_viable;
    String LED7_name;
    boolean LED7_viable;
    String LED8_name;
    boolean LED8_viable;
    private Button Mconnectb;
    private Button Mode_changb;
    boolean P1_viable;
    boolean P2_viable;
    boolean P3_viable;
    boolean P4_viable;
    boolean P5_viable;
    boolean P6_viable;
    public byte[] PPM_Mode = new byte[TCP_READ];
    public int PWM_CH1 = PWM_Offset;
    public int PWM_CH2 = PWM_Offset;
    public int PWM_CH3 = PWM_Offset;
    public int PWM_CH4 = PWM_Offset;
    public int PWM_CH5 = 1000;
    public int PWM_CH6 = 1000;
    public int PWM_CH7 = 4660;
    public byte[] PWM_Mode = new byte[TCP_READ];
    public byte[] PWM_Send = new byte[19];
    private TextView RX;
    boolean R_LED = D;
    Timer RtmrBlink;
    boolean Savebytes = false;
    int Send_Code_C;
    private RotateableTextView Servo_adct;
    Slider Show_S1;
    Slider Show_S2;
    Slider Show_S3;
    ViewGroup Sliderb;
    String TCP_ADD;
    String TCP_PORT;
    private TextView TX;
    boolean T_LED = D;
    String Test = "findViewById";
    public Timer Updata_Timer;
    private Button XmodemDown;
    private Button XmodemSet;
    private Button Xmodemopen;
    Timer Xmodemtimer;
    int Xstate = idle;
    int addX;
    int addY;
    Timer autoBlink;
    int autosendtime = 0;
    View avrubd;
    private TextView back1_text;
    private TextView back2_text;
    private TextView back3_text;
    private TextView back4_text;
    private TextView back5_text;
    private TextView back6_text;
    String button10_name;
    String button10_send;
    String button11_name;
    String button11_send;
    String button12_name;
    String button12_send;
    String button1_name;
    String button1_send;
    String button2_name;
    String button2_send;
    String button3_name;
    String button3_send;
    String button4_name;
    String button4_send;
    String button5_name;
    String button5_send;
    String button6_name;
    String button6_send;
    String button7_name;
    String button7_send;
    String button8_name;
    String button8_send;
    String button9_name;
    String button9_send;
    private Button cbtnsend1;
    private Button cbtnsend10;
    private Button cbtnsend11;
    private Button cbtnsend12;
    private Button cbtnsend2;
    private Button cbtnsend3;
    private Button cbtnsend4;
    private Button cbtnsend5;
    private Button cbtnsend6;
    private Button cbtnsend7;
    private Button cbtnsend8;
    private Button cbtnsend9;
    private GraphicalView chart;
    private long clear_c;
    private Context context;
    private String csv_fname;
    File downloadf;
    Typeface face01dig;
    TextView filent;
    FileInputStream fin;
    boolean frist_ = D;
    boolean head = false;
    int i = 0;
    int index_R;
    private TextView insendst;
    Timer intansf;
    private joystick joyst;
    Timer key_ontouth;
    String lastdevice;
    private ActionBar mActionBar;
    private Animation mAnimationRight;
    private BluetoothAdapter mBluetoothAdapter = null;
    private BluetoothChatService mChatService = null;
    private String mConnectedDeviceName = null;
    private XYMultipleSeriesDataset mDataset;
    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            byte[] tcpbuf;
            int i;
            UIActivity uIActivity;
            switch (msg.what) {
                case UIActivity.xtryconnet /*1*/:
                    Log.i(UIActivity.TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
                    switch (msg.arg1) {
                        case joystick.COORDINATE_CARTESIAN /*0*/:
                        case UIActivity.xtryconnet /*1*/:
                            UIActivity.this.mTitle.setText(R.string.title_not_connected);
                            UIActivity.this.Mconnectb.setText("\u8fde\u63a5\u8bbe\u5907");
                            return;
                        case UIActivity.xconnected /*2*/:
                            UIActivity.this.mTitle.setText(R.string.title_connecting);
                            return;
                        case UIActivity.xtransfing /*3*/:
                            UIActivity.this.mTitle.setText(R.string.title_connected_to);
                            UIActivity.this.mTitle.append(UIActivity.this.mConnectedDeviceName);
                            UIActivity.this.Mconnectb.setText("\u65ad\u5f00\u8fde\u63a5");
                            return;
                        default:
                            return;
                    }
                case UIActivity.xconnected /*2*/:
                    String readMessage;
                    byte[] readBuf = (byte[]) msg.obj;
                    tcpbuf = new byte[msg.arg1];
                    for (i = 0; i < msg.arg1; i += UIActivity.xtryconnet) {
                        tcpbuf[i] = readBuf[i];
                    }
                    if (UIActivity.this.my_Text.getText().toString().length() > 4000) {
                        String nstr = UIActivity.this.my_Text.getText().toString();
                        UIActivity.this.my_Text.setText(nstr.substring(80, nstr.length()));
                    }
                    UIActivity.this.Trig_RXLED(msg.arg1);
                    UIActivity.this.decode_frame(readBuf, msg.arg1);
                    if (UIActivity.this.Savebytes) {
                        UIActivity.this.Write_CSV_File(readBuf, msg.arg1, UIActivity.this.csv_fname);
                    }
                    if (UIActivity.this.tcp_istart) {
                        UIActivity.this.mtcpconnect.TCP_Send_Bytes(tcpbuf);
                        uIActivity = UIActivity.this;
                        uIActivity.tcp_rx += msg.arg1;
                        UIActivity.this.tcpstbt.setText("\u670d\u52a1\u5df2\u542f\u52a8 RX" + String.valueOf(UIActivity.this.tcp_rx) + "b TX" + String.valueOf(UIActivity.this.tcp_tx) + "b");
                    }
                    if (UIActivity.this.HEX_EN.isChecked() != UIActivity.D) {
                        try {
                            readMessage = new String(readBuf, 0, msg.arg1, "GBK");
                        } catch (UnsupportedEncodingException e) {
                            throw new RuntimeException("Unsupported   encoding   type.");
                        }
                    } else {
                        try {
                            readMessage = UIActivity.getHexString(readBuf, 0, msg.arg1);
                        } catch (UnsupportedEncodingException e2) {
                            throw new RuntimeException("Unsupported   encoding   type.");
                        }
                    }
                    UIActivity.this.my_Text.append(readMessage);
                    if (!UIActivity.this.mscLock) {
                        UIActivity.this.tHandler.post(UIActivity.this.mScrollToBottom);
                        return;
                    }
                    return;
                case UIActivity.xend /*4*/:
                    UIActivity.this.mConnectedDeviceName = msg.getData().getString(UIActivity.DEVICE_NAME);
                    UIActivity.this.showTextToast("\u5df2\u8fde\u63a5\u5230\uff1a " + UIActivity.this.mConnectedDeviceName);
                    UIActivity.RX_Count = 0;
                    UIActivity.TX_Count = 0;
                    return;
                case UIActivity.idle /*5*/:
                    UIActivity.this.showTextToast(msg.getData().getString(UIActivity.TOAST));
                    return;
                case UIActivity.TCP_READ /*6*/:
                    byte[] readBuf2 = (byte[]) msg.obj;
                    tcpbuf = new byte[msg.arg1];
                    for (i = 0; i < msg.arg1; i += UIActivity.xtryconnet) {
                        tcpbuf[i] = readBuf2[i];
                    }
                    UIActivity.this.msendMessage(tcpbuf);
                    uIActivity = UIActivity.this;
                    uIActivity.tcp_tx += msg.arg1;
                    UIActivity.this.tcpstbt.setText("\u670d\u52a1\u5df2\u542f\u52a8 RX" + String.valueOf(UIActivity.this.tcp_rx) + "b TX" + String.valueOf(UIActivity.this.tcp_tx) + "b");
                    return;
                case UIActivity.TCP_CHANGE /*7*/:
                    Log.i(UIActivity.TAG, "TCPIP_STATE_CHANGE: " + msg.arg1);
                    switch (msg.arg1) {
                        case joystick.COORDINATE_CARTESIAN /*0*/:
                            UIActivity.this.showTextToast("TCP\u8fde\u63a5\u5df2\u65ad\u5f00.");
                            UIActivity.this.tcp_st.setText("TCP\u8fde\u63a5\u5df2\u65ad\u5f00.");
                            return;
                        case UIActivity.xtransfing /*3*/:
                            UIActivity.this.showTextToast("\u5df2\u8fde\u63a5-IP:" + UIActivity.this.TCP_ADD + "\u7aef\u53e3:" + UIActivity.this.TCP_PORT);
                            UIActivity.this.tcp_st.setText("\u5df2\u8fde\u63a5-IP:" + UIActivity.this.TCP_ADD + "\u7aef\u53e3:" + UIActivity.this.TCP_PORT);
                            return;
                        default:
                            return;
                    }
                default:
                    return;
            }
        }
    };
    LinearLayout mLayout;
    private Runnable mScrollToBottom = new Runnable() {
        @Override
        public void run() {
            int off = UIActivity.this.mLayout.getMeasuredHeight() - UIActivity.this.mScrollView.getHeight();
            if (off > 0) {
                UIActivity.this.mScrollView.scrollTo(0, off);
            }
        }
    };
    private ScrollView mScrollView;
    private Button mSendButton;
    private TextView mTitle;
    Timer msLockT;
    boolean mscLock = false;
    private XYSeries mseries;
    Tcp_connect mtcpconnect;
    TextView my_Text;
    public ProgressDialog mydialog;
    int ontouch_send = 0;
    int osc_wr = 0;
    boolean over = false;
    byte pack_num = (byte) 1;
    String partm1_name;
    float partm1_scale;
    String partm2_name;
    float partm2_scale;
    String partm3_name;
    float partm3_scale;
    String partm4_name;
    float partm4_scale;
    String partm5_name;
    float partm5_scale;
    String partm6_name;
    float partm6_scale;
    ProgressBar pb1;
    ProgressBar pb2;
    byte[] recivebuffer = new byte[1024];
    private XYMultipleSeriesRenderer renderer;
    int rey_count;
    boolean s1_viable;
    boolean s2_viable;
    boolean s3_viable;
    private Button savbutt;
    private Button savstbut;
    View send_edit;
    boolean send_enter = false;
    private XYSeries series;
    private ImageView servo_backbt;
    private ImageButton servo_modb;
    private ImageView servo_seting;
    View sevo;
    boolean sevrflag = false;
    String slider1_name;
    int slider1_value;
    String slider2_name;
    int slider2_value;
    String slider3_name;
    int slider3_value;
    View station;
    private final Handler tHandler = new Handler();
    int tansfert;
    Timer tansferuse;
    boolean tcp_istart = false;
    int tcp_rx = 0;
    TextView tcp_st;
    int tcp_tx = 0;
    View tcp_view;
    private Button tcpstbt;
    TextView textviewtemp;
    private String title = " ";
    Timer tmrBlink;
    private Toast toast = null;
    EditText usrinput;
    int wr_index = 0;
    DialogWrapper wrapper;
    byte[] x_ingtansf_buf = null;
    int x_read_offset = 0;
    String xmodecode;
    int xmodeframe;
    long xmodeframec;
    long xmodeframett;
    private TextView xmodemfile;
    String xmodemlastfile;
    private TextView xmodemsetting;
    int xmoderetry;
    int xmodetime;
    int[] xv = new int[1000];
    int[] yv = new int[1000];

    @Override
    @SuppressLint({"NewApi"})
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (VERSION.SDK_INT > 9) {
            StrictMode.setThreadPolicy(new Builder().permitAll().build());
        }
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        ((FloatingActionButton) findViewById(R.id.fab)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", 0).setAction("Action", null).show();
            }
        });
        mGson = new GsonBuilder()
                .registerTypeAdapter(NewBean.class, new SensorTypeAdapter())
                //registerTypeAdapter可以重复使用
                .create();
        setTitle("\u84dd\u7259\u4e32\u53e3\u52a9\u624b");
        this.context = getApplicationContext();
        this.PPM_Mode[0] = (byte) -91;
        this.PPM_Mode[xtryconnet] = (byte) 90;
        this.PPM_Mode[xconnected] = (byte) 4;
        this.PPM_Mode[xtransfing] = (byte) -3;
        this.PPM_Mode[xend] = (byte) 1;
        this.PPM_Mode[idle] = LED_SERVO_COMMAND;
        this.PWM_Mode[0] = (byte) -91;
        this.PWM_Mode[xtryconnet] = (byte) 90;
        this.PWM_Mode[xconnected] = (byte) 4;
        this.PWM_Mode[xtransfing] = (byte) -3;
        this.PWM_Mode[xend] = LED_SERVO_COMMAND;
        this.PWM_Mode[idle] = (byte) 3;
        this.mtcpconnect = new Tcp_connect(this, this.mHandler);
        this.face01dig = Typeface.createFromAsset(getAssets(), "01digigraphics.ttf");
        this.tcp_st = (TextView) findViewById(R.id.tcp_stauts);
        this.my_Text = (TextView) findViewById(R.id.Text1);
        this.RX = (TextView) findViewById(R.id.RX_C);
        this.TX = (TextView) findViewById(R.id.TX_C);
        this.usrinput = (EditText) findViewById(R.id.entry);
        this.RX.setTypeface(this.face01dig);
        this.TX.setTypeface(this.face01dig);
        this.filent = (TextView) findViewById(R.id.savefinf);
        this.mScrollView = (ScrollView) findViewById(R.id.sv);
        this.mLayout = (LinearLayout) findViewById(R.id.layout);
        this.Edit1 = (EditText) findViewById(R.id.entry);
        this.mTitle = (TextView) findViewById(R.id.ST);
        this.station = findViewById(R.id.station);
        this.avrubd = findViewById(R.id.avrxmodem);
        this.sevo = findViewById(R.id.servo_lat);
        this.send_edit = findViewById(R.id.sed_air);
        this.tcp_view = findViewById(R.id.tcp_face);
        this.joyst = (joystick) findViewById(R.id.controljoy);
        this.sevo.setVisibility(View.INVISIBLE);
        this.avrubd.setVisibility(View.INVISIBLE);
        this.station.setVisibility(View.INVISIBLE);
        setupLedController(xtryconnet, R.id.sliders);
        this.Sliderb = (ViewGroup) findViewById(R.id.sliders);
        this.textviewtemp = (TextView) ((ViewGroup) this.Sliderb.getChildAt(0)).getChildAt(0);
        this.textviewtemp.setText("PID.P");
        this.textviewtemp = (TextView) ((ViewGroup) this.Sliderb.getChildAt(xtryconnet)).getChildAt(0);
        this.textviewtemp.setText("PID.I");
        this.textviewtemp = (TextView) ((ViewGroup) this.Sliderb.getChildAt(xconnected)).getChildAt(0);
        this.textviewtemp.setText("PID.D");
        this.cbtnsend1 = (Button) findViewById(R.id.buttons1);
        this.cbtnsend2 = (Button) findViewById(R.id.buttons2);
        this.cbtnsend3 = (Button) findViewById(R.id.buttons3);
        this.cbtnsend4 = (Button) findViewById(R.id.buttons4);
        this.cbtnsend5 = (Button) findViewById(R.id.buttons5);
        this.cbtnsend6 = (Button) findViewById(R.id.buttons6);
        this.cbtnsend7 = (Button) findViewById(R.id.buttons7);
        this.cbtnsend8 = (Button) findViewById(R.id.buttons8);
        this.cbtnsend9 = (Button) findViewById(R.id.buttons9);
        this.cbtnsend10 = (Button) findViewById(R.id.buttons10);
        this.cbtnsend11 = (Button) findViewById(R.id.buttons11);
        this.cbtnsend12 = (Button) findViewById(R.id.buttons12);
        this.back1_text = (TextView) findViewById(R.id.backtext1);
        this.back2_text = (TextView) findViewById(R.id.backtext2);
        this.back3_text = (TextView) findViewById(R.id.backtext3);
        this.back4_text = (TextView) findViewById(R.id.backtext4);
        this.back5_text = (TextView) findViewById(R.id.backtext5);
        this.back6_text = (TextView) findViewById(R.id.backtext6);
        this.Xmodemopen = (Button) findViewById(R.id.openf);
        this.XmodemSet = (Button) findViewById(R.id.xmodemset);
        this.XmodemDown = (Button) findViewById(R.id.xmodemdown);
        this.xmodemfile = (TextView) findViewById(R.id.filer);
        this.xmodemsetting = (TextView) findViewById(R.id.xmseting);
        this.pb1 = (ProgressBar) findViewById(R.id.pbar1);
        this.pb2 = (ProgressBar) findViewById(R.id.pbar2);
        this.insendst = (TextView) findViewById(R.id.stpersand);
        this.servo_modb = (ImageButton) findViewById(R.id.servo_back);
        this.Mode_changb = (Button) findViewById(R.id.changm);
        this.savbutt = (Button) findViewById(R.id.record_name);
        this.savstbut = (Button) findViewById(R.id.recodest);
        this.servo_backbt = (ImageView) findViewById(R.id.im_back);
        this.servo_seting = (ImageView) findViewById(R.id.servo_set);
        initial_Sation();
        initial_xmodem();
        this.HEX_EN = (CheckBox) findViewById(R.id.checkbox1);
        registerForContextMenu(this.my_Text);
        this.RX.setText("RX 0");
        this.TX.setText("TX 0");
        this.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (this.mBluetoothAdapter == null) {
            showTextToast("\u6ca1\u6709\u53d1\u73b0\u84dd\u7259\u6a21\u5757,\u7a0b\u5e8f\u4e2d\u6b62");
            finish();
            return;
        }
        this.HEX_EN.setTextColor(getResources().getColor(R.color.Baclk));
        this.HEX_EN.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                String distext = " ";
                if (isChecked) {
                    UIActivity.this.Edit1.setHint("31 FE 5B");
                    return;
                }
                UIActivity.this.Edit1.setHint("ASCII  ");
            }
        });
        this.tmrBlink = new Timer(100, new Runnable() {
            @Override
            public void run() {
                UIActivity.this.RX.setBackgroundColor(UIActivity.this.getResources().getColor(R.color.LED_G_OFF));
                UIActivity.this.RX.setTextColor(UIActivity.this.getResources().getColor(R.color.white_));
                UIActivity.this.tmrBlink.stop();
            }
        });
        this.RtmrBlink = new Timer(100, new Runnable() {
            @Override
            public void run() {
                UIActivity.this.TX.setBackgroundColor(UIActivity.this.getResources().getColor(R.color.LED_R_OFF));
                UIActivity.this.TX.setTextColor(UIActivity.this.getResources().getColor(R.color.white_));
                UIActivity.this.RtmrBlink.stop();
            }
        });
        this.autoBlink = new Timer(1000, new Runnable() {
            @Override
            public void run() {
                String message = UIActivity.this.usrinput.getText().toString();
                if (UIActivity.this.send_enter == UIActivity.D && !UIActivity.this.HEX_EN.isChecked()) {
                    message = message + "\r\n";
                }
                if (!message.equals(BuildConfig.FLAVOR) && UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    newBean = new NewBean(new ArrayList<Encoder>(), 5, "W");
                    String message1 = "&" + mGson.toJson(newBean) + "&";
                    UIActivity.this.sendMessage(message1);
                }
            }
        });
        this.autoBlink.stop();
        ((Button) findViewById(R.id.osc_data)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Random random = new Random();
                UIActivity.this.mdraw_osc(random.nextInt(260));
                UIActivity.this.mdraw_osc(random.nextInt(260));
                UIActivity.this.mdraw_osc(random.nextInt(260));
                UIActivity.this.mdraw_osc(random.nextInt(260));
                UIActivity.this.mdraw_osc(random.nextInt(260));
                UIActivity.this.mdraw_osc(random.nextInt(260));
                UIActivity.this.mdraw_osc(random.nextInt(260));
            }
        });
        this.intansf = new Timer(3000, new Runnable() {
            @Override
            public void run() {
                if (UIActivity.this.Xstate == UIActivity.xtransfing) {
                    UIActivity.this.XmodemDown.setText("\u76ee\u6807\u63a5\u6536\u7b2c " + UIActivity.this.xmodeframec + " \u5e27\u8d85\u65f6(3S) \u4e2d\u6b62\u4f20\u9001");
                    UIActivity.this.Send_Xmode_End();
                    UIActivity.this.Xstate = UIActivity.idle;
                    UIActivity.this.insendst.setVisibility(View.GONE);
                    UIActivity.this.pb2.setVisibility(View.GONE);
                    UIActivity.this.Xmodemopen.setEnabled(UIActivity.D);
                    UIActivity.this.XmodemSet.setEnabled(UIActivity.D);
                }
                UIActivity.this.intansf.stop();
            }
        });
        this.intansf.stop();
        this.tansferuse = new Timer(100, new Runnable() {
            @Override
            public void run() {
                if (UIActivity.this.Xstate == UIActivity.xtransfing) {
                    UIActivity uIActivity = UIActivity.this;
                    uIActivity.tansfert += UIActivity.xtryconnet;
                    float tempf = ((float) UIActivity.this.tansfert) / 10.0f;
                    if (UIActivity.this.rey_count == 0) {
                        UIActivity.this.insendst.setText(UIActivity.this.xmodeframett + " / " + UIActivity.this.xmodeframec + " \u8017\u65f6:" + tempf + "S");
                        return;
                    } else {
                        UIActivity.this.insendst.setText(UIActivity.this.xmodeframett + " / " + UIActivity.this.xmodeframec + " \u8017\u65f6:" + tempf + "S \u91cd\u4f20" + UIActivity.this.rey_count + "\u6b21");
                        return;
                    }
                }
                UIActivity.this.tansferuse.stop();
            }
        });
        this.tansferuse.stop();
        this.Xmodemtimer = new Timer(1000, new Runnable() {
            @Override
            public void run() {
                UIActivity uIActivity = UIActivity.this;
                uIActivity.Send_Code_C += UIActivity.xtryconnet;
                if (UIActivity.this.Xstate != UIActivity.xtryconnet) {
                    UIActivity.this.Xmodemtimer.stop();
                } else if (UIActivity.this.Send_Code_C <= UIActivity.this.xmoderetry) {
                    byte[] send = UIActivity.this.getStringhex(UIActivity.this.xmodecode);
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                    UIActivity.this.XmodemDown.setText("\u6b63\u5728\u8054\u673a...\u7b2c" + UIActivity.this.Send_Code_C + "\u6b21\u5c1d\u8bd5");
                    UIActivity.this.Xmodemtimer.setInterval(UIActivity.this.xmodetime);
                } else if (UIActivity.this.XmodemDown.getText() == "\u8054\u673a\u5931\u8d25") {
                    UIActivity.this.XmodemDown.setText("\u4e0b\u8f7d");
                    UIActivity.this.Xmodemtimer.stop();
                } else if (UIActivity.this.XmodemDown.getText() == "\u4e0b\u8f7d") {
                    UIActivity.this.Xmodemtimer.stop();
                } else {
                    UIActivity.this.XmodemDown.setText("\u8054\u673a\u5931\u8d25");
                    UIActivity.this.Xmodemtimer.setInterval(2000);
                    UIActivity.this.Xmodemopen.setEnabled(UIActivity.D);
                    UIActivity.this.XmodemSet.setEnabled(UIActivity.D);
                    UIActivity.this.Xstate = UIActivity.idle;
                }
            }
        });
        this.Xmodemtimer.stop();
        this.savbutt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                UIActivity.this.nameSeting("\u4fee\u6539\u6587\u4ef6\u540d", UIActivity.this.csv_fname);
            }
        });
        this.savstbut.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (UIActivity.this.Savebytes) {
                    UIActivity.this.Savebytes = false;
                    UIActivity.this.savstbut.setText("\u6570\u636e\u8bb0\u5f55\u5df2\u505c\u6b62");
                    return;
                }
                UIActivity.this.Savebytes = UIActivity.D;
                UIActivity.this.savstbut.setText("\u6b63\u5728\u8bb0\u5f55\u4e2d...");
            }
        });
        ((Button) findViewById(R.id.tcp_connect)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                UIActivity.this.startActivityForResult(new Intent(UIActivity.this, TCP_linkActivity.class), UIActivity.xtransfing);
            }
        });
        Button temp = (Button) findViewById(R.id.tcp_start);
        this.tcpstbt = temp;
        temp.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Button temp2 = (Button) UIActivity.this.findViewById(R.id.tcp_start);
                if (UIActivity.this.mtcpconnect.get_stauts() != UIActivity.xtransfing) {
                    UIActivity.this.showTextToast("\u8bf7\u5148\u8fde\u63a5TCP\u670d\u52a1\u5668");
                } else if (UIActivity.this.tcp_istart) {
                    UIActivity.this.tcp_istart = false;
                    temp2.setText("\u670d\u52a1\u5df2\u505c\u6b62");
                    UIActivity.this.tcp_st.setText("\u5df2\u8fde\u63a5-IP:" + UIActivity.this.TCP_ADD + "\u7aef\u53e3:" + UIActivity.this.TCP_PORT + "\r\n\u6570\u636e\u4f20\u9001\u5df2\u505c\u6b62");
                } else {
                    UIActivity.this.tcp_istart = UIActivity.D;
                    UIActivity.this.tcp_tx = 0;
                    UIActivity.this.tcp_rx = 0;
                    UIActivity.this.tcpstbt.setText("\u670d\u52a1\u5df2\u542f\u52a8 RX" + String.valueOf(UIActivity.this.tcp_rx) + "b TX" + String.valueOf(UIActivity.this.tcp_tx) + "b");
                    UIActivity.this.tcp_st.setText("\u5df2\u8fde\u63a5-IP:" + UIActivity.this.TCP_ADD + "\u7aef\u53e3:" + UIActivity.this.TCP_PORT + "\r\n\u6570\u636e\u4f20\u9001\u5df2\u542f\u52a8");
                }
            }
        });
        this.Updata_Timer = new Timer(20, new Runnable() {
            @Override
            public void run() {
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    int sum = 0;
                    UIActivity.this.PWM_Send[0] = (byte) -91;
                    UIActivity.this.PWM_Send[UIActivity.xtryconnet] = (byte) 90;
                    UIActivity.this.PWM_Send[UIActivity.xconnected] = (byte) 17;
                    UIActivity.this.PWM_Send[UIActivity.xtransfing] = (byte) -11;
                    UIActivity.this.PWM_Send[UIActivity.xend] = (byte) ((UIActivity.this.PWM_CH1 >> 8) & 255);
                    UIActivity.this.PWM_Send[UIActivity.idle] = (byte) (UIActivity.this.PWM_CH1 & 255);
                    UIActivity.this.PWM_Send[UIActivity.TCP_READ] = (byte) ((UIActivity.this.PWM_CH2 >> 8) & 255);
                    UIActivity.this.PWM_Send[UIActivity.TCP_CHANGE] = (byte) (UIActivity.this.PWM_CH2 & 255);
                    UIActivity.this.PWM_Send[8] = (byte) ((UIActivity.this.PWM_CH3 >> 8) & 255);
                    UIActivity.this.PWM_Send[9] = (byte) (UIActivity.this.PWM_CH3 & 255);
                    UIActivity.this.PWM_Send[10] = (byte) ((UIActivity.this.PWM_CH4 >> 8) & 255);
                    UIActivity.this.PWM_Send[11] = (byte) (UIActivity.this.PWM_CH4 & 255);
                    UIActivity.this.PWM_Send[12] = (byte) ((UIActivity.this.PWM_CH5 >> 8) & 255);
                    UIActivity.this.PWM_Send[13] = (byte) (UIActivity.this.PWM_CH5 & 255);
                    UIActivity.this.PWM_Send[14] = (byte) ((UIActivity.this.PWM_CH6 >> 8) & 255);
                    UIActivity.this.PWM_Send[15] = (byte) (UIActivity.this.PWM_CH6 & 255);
                    UIActivity.this.PWM_Send[16] = (byte) ((UIActivity.this.PWM_CH7 >> 8) & 255);
                    UIActivity.this.PWM_Send[17] = (byte) (UIActivity.this.PWM_CH7 & 255);
                    for (int i = UIActivity.xconnected; i < 18; i += UIActivity.xtryconnet) {
                        sum += UIActivity.this.PWM_Send[i];
                    }
                    UIActivity.this.PWM_Send[18] = (byte) (sum & 255);
                    if (UIActivity.this.BL_Mode == UIActivity.xend) {
                        UIActivity.this.mChatService.write(UIActivity.this.PWM_Send);
                        UIActivity.this.Trig_TXLED(UIActivity.this.PWM_Send.length);
                        return;
                    }
                    UIActivity.this.Updata_Timer.stop();
                }
            }
        });
        this.Updata_Timer.stop();
        this.mSendButton = (Button) findViewById(R.id.ok);
        mSendButton.setOnTouchListener(this);
//        this.mSendButton.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                String message = ((TextView) UIActivity.this.findViewById(R.id.entry)).getText().toString();
//                if (UIActivity.this.send_enter && UIActivity.this.HEX_EN.isChecked() != UIActivity.D) {
//                    message = message + "\r\n";
//                }
//                UIActivity.this.sendMessage(message);
//            }
//        });


        this.Mconnectb = (Button) findViewById(R.id.nnectin);
        this.Mconnectb.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (UIActivity.this.mChatService.getState() != UIActivity.xtransfing) {
                    UIActivity.this.startActivityForResult(new Intent(UIActivity.this.getApplicationContext(), DeviceListActivity.class), UIActivity.xtryconnet);
                    return;
                }
                UIActivity.this.mChatService.stop();
            }
        });
        this.csv_fname = getSharedPreferences("perference", 0).getString("lastfile_name", BuildConfig.FLAVOR);
        if (this.csv_fname == BuildConfig.FLAVOR) {
            this.csv_fname = "\u4e8c\u8fdb\u5236\u6570\u636e";
        }
        this.filent.setText("\u6587\u4ef6\u540d:" + this.csv_fname + ".txt");
        this.XmodemDown.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (UIActivity.this.Xstate == UIActivity.idle) {
                    UIActivity.this.Xmodemtimer.stop();
                    if (UIActivity.this.mChatService.getState() != UIActivity.xtransfing) {
                        UIActivity.this.showTextToast("\u8bf7\u5148\u8fde\u63a5\u8bbe\u5907");
                        return;
                    }
                    UIActivity.this.Send_Code_C = UIActivity.xtryconnet;
                    byte[] send = UIActivity.this.getStringhex(UIActivity.this.xmodecode);
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                    UIActivity.this.XmodemDown.setText("\u6b63\u5728\u8054\u673a...\u7b2c" + UIActivity.this.Send_Code_C + "\u6b21\u5c1d\u8bd5");
                    UIActivity.this.Xstate = UIActivity.xtryconnet;
                    UIActivity.this.Xmodemtimer.setInterval(UIActivity.this.xmodetime);
                    UIActivity.this.Xmodemtimer.start();
                    UIActivity.this.Xmodemopen.setEnabled(false);
                    UIActivity.this.XmodemSet.setEnabled(false);
                    UIActivity.this.x_read_offset = 0;
                    UIActivity.this.tansfert = 0;
                }
            }
        });
        this.Xmodemopen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                FileOpenerDialog dlg = new FileOpenerDialog(UIActivity.this, UIActivity.xtryconnet, null, "txt", UIActivity.this);
                dlg.requestWindowFeature(UIActivity.xtryconnet);
                dlg.setTitle("\u9009\u62e9\u6587\u4ef6");
                dlg.show();
            }
        });
        this.XmodemSet.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                View addView = LayoutInflater.from(UIActivity.this).inflate(R.layout.xmodemsset, null);
                final DialogWrapper2 wrapper = new DialogWrapper2(addView);
                wrapper.setcode(UIActivity.this.xmodecode);
                wrapper.setdatalong(String.valueOf(UIActivity.this.xmodeframe));
                wrapper.setdatatime(String.valueOf(UIActivity.this.xmodetime));
                wrapper.setretryc(String.valueOf(UIActivity.this.xmoderetry));
                new AlertDialog.Builder(UIActivity.this).setTitle("XMODEM\u91cd\u8981\u7684\u8bbe\u7f6e").setView(addView).setPositiveButton("\u786e\u5b9a", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String temp = wrapper.getdatalong();
                        if (UIActivity.isNumeric(temp) && Integer.valueOf(temp).intValue() <= 1024) {
                            UIActivity.this.xmodeframe = Integer.valueOf(temp).intValue();
                        }
                        temp = wrapper.getdatatime();
                        if (UIActivity.isNumeric(temp) && Integer.valueOf(temp).intValue() < 2000) {
                            UIActivity.this.xmodetime = Integer.valueOf(temp).intValue();
                        }
                        temp = wrapper.getretryc();
                        if (UIActivity.isNumeric(temp)) {
                            UIActivity.this.xmoderetry = Integer.valueOf(temp).intValue();
                        }
                        temp = wrapper.getcode();
                        if (UIActivity.this.isHEX(temp)) {
                            UIActivity.this.xmodecode = temp;
                        }
                        UIActivity.this.writexmodemseting();
                        UIActivity.this.initial_xmodem();
                        UIActivity.this.Xstate = UIActivity.idle;
                    }
                }).setNegativeButton("\u53d6\u6d88", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                }).show();
            }
        });
        this.Mode_changb.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                UIActivity.this.Mode_chagned();
            }
        });
        this.cbtnsend1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button1_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button2_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button3_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend4.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button4_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend5.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button5_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend6.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button6_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend7.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button7_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend8.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button8_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend9.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button9_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend10.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button10_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend11.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button11_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.cbtnsend12.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                byte[] send = UIActivity.this.getStringhex(UIActivity.this.button12_send);
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.key_ontouth = new Timer(idle, new Runnable() {
            @Override
            public void run() {
                byte[] send = null;
                switch (UIActivity.this.ontouch_send) {
                    case joystick.COORDINATE_CARTESIAN /*0*/:
                        send = new byte[UIActivity.TCP_READ];
                        send[0] = (byte) -91;
                        send[UIActivity.xtryconnet] = (byte) 90;
                        send[UIActivity.xconnected] = (byte) 4;
                        send[UIActivity.xtransfing] = (byte) -80;
                        send[UIActivity.xend] = (byte) -76;
                        send[UIActivity.idle] = (byte) -86;
                        break;
                    case UIActivity.xtryconnet /*1*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button1_send);
                        break;
                    case UIActivity.xconnected /*2*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button2_send);
                        break;
                    case UIActivity.xtransfing /*3*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button3_send);
                        break;
                    case UIActivity.xend /*4*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button4_send);
                        break;
                    case UIActivity.idle /*5*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button5_send);
                        break;
                    case 6:
                        send = UIActivity.this.getStringhex(UIActivity.this.button6_send);
                        break;
                    case UIActivity.TCP_CHANGE /*7*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button7_send);
                        break;
                    case R.styleable.Toolbar_contentInsetRight /*8*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button8_send);
                        break;
                    case 9 /*9*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button9_send);
                        break;
                    case 10/*10*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button10_send);
                        break;
                    case R.styleable.Toolbar_popupTheme /*11*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button11_send);
                        break;
                    case R.styleable.Toolbar_titleTextAppearance /*12*/:
                        send = UIActivity.this.getStringhex(UIActivity.this.button12_send);
                        break;
                    default:
                        UIActivity.this.ontouch_send = 0;
                        break;
                }
                if (UIActivity.this.mChatService.getState() == UIActivity.xtransfing) {
                    UIActivity.this.Trig_TXLED(send.length);
                    UIActivity.this.mChatService.write(send);
                }
            }
        });
        this.key_ontouth.stop();
        load_last_mode();
        initial_osc();
        is_conect();
        this.mScrollView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case joystick.COORDINATE_CARTESIAN /*0*/:
                        UIActivity.this.mscLock = UIActivity.D;
                        break;
                    case UIActivity.xtryconnet /*1*/:
                        UIActivity.this.mscLock = UIActivity.D;
                        UIActivity.this.msLockT.restart();
                        break;
                    default:
                        UIActivity.this.msLockT.restart();
                        break;
                }
                return false;
            }
        });
        this.msLockT = new Timer(3000, new Runnable() {
            @Override
            public void run() {
                UIActivity.this.mscLock = false;
                UIActivity.this.msLockT.stop();
            }
        });
    }

    public void Try_clear(View v) {
        if (System.currentTimeMillis() - this.clear_c > 1200) {
            showTextToast("1\u79d2\u5185\u53cc\u51fb\u6587\u5b57\uff0c\u5c06\u6e05\u9664\u663e\u793a\u533a\u6570\u636e");
            this.clear_c = System.currentTimeMillis();
            return;
        }
        this.my_Text.setText(BuildConfig.FLAVOR);
    }

    @SuppressLint("WrongConstant")
    private void showTextToast(String msg) {
        if (this.toast == null) {
            this.toast = Toast.makeText(getApplicationContext(), msg, xtryconnet);
            this.toast.setText(msg);
        } else {
            this.toast.setText(msg);
        }
        this.toast.show();
    }

    void send_butt() {
        byte[] send = null;
        switch (this.ontouch_send) {
            case joystick.COORDINATE_CARTESIAN /*0*/:
                send = new byte[TCP_READ];
                send[0] = (byte) -91;
                send[xtryconnet] = (byte) 90;
                send[xconnected] = (byte) 4;
                send[xtransfing] = (byte) -80;
                send[xend] = (byte) -76;
                send[idle] = (byte) -86;
                break;
            case xtryconnet /*1*/:
                send = getStringhex(this.button1_send);
                break;
            case xconnected /*2*/:
                send = getStringhex(this.button2_send);
                break;
            case xtransfing /*3*/:
                send = getStringhex(this.button3_send);
                break;
            case xend /*4*/:
                send = getStringhex(this.button4_send);
                break;
            case idle /*5*/:
                send = getStringhex(this.button5_send);
                break;
            case 6 /*6*/:
                send = getStringhex(this.button6_send);
                break;
            case TCP_CHANGE /*7*/:
                send = getStringhex(this.button7_send);
                break;
            case R.styleable.Toolbar_contentInsetRight /*8*/:
                send = getStringhex(this.button8_send);
                break;
            case 9 /*9*/:
                send = getStringhex(this.button9_send);
                break;
            case 10 /*10*/:
                send = getStringhex(this.button10_send);
                break;
            case R.styleable.Toolbar_popupTheme /*11*/:
                send = getStringhex(this.button11_send);
                break;
            case R.styleable.Toolbar_titleTextAppearance /*12*/:
                send = getStringhex(this.button12_send);
                break;
            default:
                this.ontouch_send = 13;
                break;
        }
        if (this.mChatService.getState() == xtransfing) {
            Trig_TXLED(send.length);
            this.mChatService.write(send);
        }
    }

    void Save_config(String name, String Value) {
        Editor editor = getSharedPreferences("perference", 0).edit();
        editor.putString(name, Value);
        editor.commit();
    }

    void is_conect() {
        this.lastdevice = getSharedPreferences("perference", 0).getString("lastdevice_addr", BuildConfig.FLAVOR);
        new AlertDialog.Builder(this).setTitle("\u8fde\u63a5\u8bf7\u6c42").setIcon(R.drawable.avrubd1).setMessage("\u8f6f\u4ef6\u5e76\u6ca1\u6709\u8fde\u63a5\u84dd\u7259\u8bbe\u5907\uff0c\u8bf7\u8fde\u63a5\u8bbe\u5907").setPositiveButton("\u8fde\u63a5\u4e0a\u6b21\u7684\u8bbe\u5907", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (UIActivity.this.lastdevice == BuildConfig.FLAVOR) {
                    UIActivity.this.startActivityForResult(new Intent(UIActivity.this.getApplicationContext(), DeviceListActivity.class), UIActivity.xtryconnet);
                    return;
                }
                Log.d(UIActivity.TAG, "\u8fde\u63a5\u5230\u6700\u8fd1\u7684\u8bbe\u5907" + UIActivity.this.lastdevice);
                UIActivity.this.mChatService.connect(UIActivity.this.mBluetoothAdapter.getRemoteDevice(UIActivity.this.lastdevice));
            }
        }).setNegativeButton("\u8fde\u63a5\u65b0\u7684\u8bbe\u5907", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                UIActivity.this.startActivityForResult(new Intent(UIActivity.this.getApplicationContext(), DeviceListActivity.class), UIActivity.xtryconnet);
            }
        }).show();
    }

    public void servo_slider(int index, int value) {
    }

    private void setupSliderController(int index, int viewId, String dan_wer, int ofset, boolean ismax) {
        Slidercontroller ledC = new Slidercontroller(this, index, getResources(), false);
        ledC.set_bascv(dan_wer, ofset);
        ledC.setnomax(ismax);
        ledC.attachToView((ViewGroup) findViewById(viewId), index);
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.e(TAG, "++ ON START ++");
        if (!this.mBluetoothAdapter.isEnabled()) {
            startActivityForResult(new Intent("android.bluetooth.adapter.action.REQUEST_ENABLE"), xconnected);
        } else if (this.mChatService == null) {
            setupChat();
        }
    }

    @Override
    public synchronized void onPause() {
        super.onPause();
        Log.e(TAG, "- ON PAUSE -");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.e(TAG, "-- ON STOP --");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (this.mChatService != null) {
            this.mChatService.stop();
        }
        Log.e(TAG, "--- ON DESTROY ---");
    }

    @Override
    public synchronized void onResume() {
        super.onResume();
        Log.e(TAG, "+ ON RESUME +");
        if (this.mChatService != null && this.mChatService.getState() == 0) {
            this.mChatService.start();
        }
    }

    private void setupChat() {
        Log.d(TAG, "setupConnect()");
        this.mChatService = new BluetoothChatService(this, this.mHandler);
    }

    private void sendMessage(String message) {
        if (this.mChatService.getState() == xtransfing && message != null && message.length() > 0) {
            byte[] send = null;
            if (this.HEX_EN.isChecked() != D) {
                try {
                    send = message.getBytes("GBK");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            } else {
                send = getStringhex(message);
            }
//            Trig_TXLED(send.length);
            this.mChatService.write(send);
        }
    }

    private void msendMessage(byte[] send) {
        if (this.mChatService.getState() == xtransfing) {
            Trig_TXLED(send.length);
            this.mChatService.write(send);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult " + resultCode);
        String address;
        switch (requestCode) {
            case xtryconnet /*1*/:
                if (resultCode == -1) {
                    address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
                    Save_config("lastdevice_addr", address);
                    this.mChatService.connect(this.mBluetoothAdapter.getRemoteDevice(address));
                    return;
                }
                return;
            case xconnected /*2*/:
                if (resultCode == -1) {
                    setupChat();
                    return;
                }
                Log.d(TAG, "Bluetooth not enabled");
                showTextToast("\u84dd\u7259\u529f\u80fd\u6ca1\u6709\u6253\u5f00,\u7a0b\u5e8f\u65e0\u6cd5\u8fd0\u884c");
                finish();
                return;
            case xtransfing /*3*/:
                if (resultCode == -1) {
                    address = data.getExtras().getString(TCP_linkActivity.EXTRA_TCP_ADDRESS);
                    this.TCP_ADD = address;
                    String port = data.getExtras().getString(TCP_linkActivity.EXTRA_TCP_PORT);
                    this.TCP_PORT = port;
                    Log.d(TAG, address + "@" + port);
                    this.mtcpconnect.MTCP_Connect(address, Integer.valueOf(port).intValue());
                    return;
                }
                return;
            case R.styleable.Toolbar_contentInsetEndWithActions /*10*/:
                initial_Sation();
                return;
            default:
                return;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @SuppressLint("WrongConstant")
    private void ensureDiscoverable() {
        Log.d(TAG, "ensure discoverable");
        if (this.mBluetoothAdapter.getScanMode() != 23) {
            Intent discoverableIntent = new Intent("android.bluetooth.adapter.action.REQUEST_DISCOVERABLE");
            discoverableIntent.putExtra("android.bluetooth.adapter.extra.DISCOVERABLE_DURATION", 300);
            startActivity(discoverableIntent);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.stationcv /*2131558679*/:
                Mode_chagned();
                return D;
            case R.id.scan /*2131558680*/:
                if (this.mChatService.getState() != xtransfing) {
                    startActivityForResult(new Intent(getApplicationContext(), DeviceListActivity.class), xtryconnet);
                    return D;
                }
                this.mChatService.stop();
                return D;
            case R.id.about /*2131558681*/:
                ShowAbout();
                return D;
            case R.id.Save /*2131558682*/:
                WriteFile(this.my_Text.getText().toString(), "FUCK");
                return D;
            case R.id.setting /*2131558683*/:
                startActivityForResult(new Intent(this, SettingActivity.class), 10);
                return D;
            case R.id.snedcofi /*2131558684*/:
                SendSeting("\u8bbe\u7f6e\u5b9a\u65f6\u53d1\u9001", String.valueOf(this.autosendtime));
                return D;
            case R.id.resetc /*2131558685*/:
                RX_Count = 0;
                TX_Count = 0;
                this.TX.setText("TX " + TX_Count);
                this.RX.setText("RX " + RX_Count);
                return D;
            case R.id.item1 /*2131558686*/:
                if (this.send_enter) {
                    this.send_enter = false;
                    showTextToast("\u53d6\u6d88\u53d1\u9001ASCII\u65f6\u5e26\u56de\u8f66\u53d1\u9001");
                    return D;
                }
                this.send_enter = D;
                showTextToast("\u53d1\u9001ASCII\u65f6\u5e26\u56de\u8f66\u53d1\u9001");
                return D;
            default:
                return false;
        }
    }

    public boolean isaNumeric(String str) {
        for (int i = 0; i < str.length(); i += xtryconnet) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return D;
    }

    private void SendSeting(String Title, String value) {
        View addView = LayoutInflater.from(this).inflate(R.layout.add_editsen, null);
        this.wrapper = new DialogWrapper(addView);
        this.wrapper.setnametext(value);
        new AlertDialog.Builder(this).setTitle(Title).setView(addView).setPositiveButton("\u786e\u5b9a", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                String str = UIActivity.this.wrapper.getTitleField().getText().toString();
                Log.d("UI", "autosendtime: " + str);
                if (UIActivity.this.isaNumeric(str)) {
                    UIActivity.this.autosendtime = Integer.valueOf(str).intValue();
                    Log.d("UI", "this is number " + str);
                    if (UIActivity.this.autosendtime != 0) {
                        UIActivity.this.autoBlink.stop();
                        UIActivity.this.autoBlink.setInterval(UIActivity.this.autosendtime);
                        UIActivity.this.autoBlink.start();
                    } else {
                        UIActivity.this.autoBlink.stop();
                        UIActivity.this.autosendtime = 0;
                    }
                } else {
                    UIActivity.this.showTextToast("\u4fee\u6539\u5931\u8d25\r\n\u8bf7\u8f93\u5165\u6570\u5b57");
                }
                Log.d("UI", "Dialog finish !");
            }
        }).setNegativeButton("\u53d6\u6d88", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        }).show();
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        AlertDialog.Builder title = new AlertDialog.Builder(this).setTitle("\u84dd\u7259\u4e32\u53e3");
        CharSequence[] charSequenceArr = new String[xtransfing];
        charSequenceArr[0] = "\u6e05\u9664\u63a5\u6536\u533a";
        charSequenceArr[xtryconnet] = "\u4fdd\u5b58\u63a5\u6536\u533a";
        charSequenceArr[xconnected] = "\u7a0b\u5e8f\u5e2e\u52a9";
        title.setItems(charSequenceArr, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case joystick.COORDINATE_CARTESIAN /*0*/:
                        dialog.dismiss();
                        UIActivity.this.my_Text.setText(BuildConfig.FLAVOR);
                        UIActivity.RX_Count = 0;
                        UIActivity.this.RX.setText("RX " + UIActivity.RX_Count);
                        break;
                    case UIActivity.xtryconnet /*1*/:
                        UIActivity.this.WriteFile(UIActivity.this.my_Text.getText().toString(), "FUCK");
                        break;
                    case UIActivity.xconnected /*2*/:
                        UIActivity.this.ShowAbout();
                        break;
                }
                dialog.dismiss();
            }
        }).show();
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case joystick.COORDINATE_CARTESIAN /*0*/:
                WriteFile(this.my_Text.getText().toString(), "FUCK");
                break;
            case xtryconnet /*1*/:
                this.my_Text.setText(BuildConfig.FLAVOR);
                RX_Count = 0;
                this.RX.setText("RX " + RX_Count);
                break;
            case xconnected /*2*/:
                showTextToast("E-mail:lis3188@163.com");
                break;
        }
        return super.onContextItemSelected(item);
    }

    public void WriteFile(String s, String name) {
        name = Get_number(Calendar.getInstance().getTime().toLocaleString());
        File destDir = new File("/sdcard/Com Save");
        if (!destDir.exists()) {
            destDir.mkdirs();
        }
        if (s.length() == 0) {
            showTextToast("\u63a5\u6536\u533a\u7a7a,\u6ca1\u6709\u6570\u636e\u4fdd\u5b58");
            return;
        }
        try {
            FileOutputStream outStream = new FileOutputStream("/sdcard/Com Save/" + name + ".txt", D);
            OutputStreamWriter writer = new OutputStreamWriter(outStream, "gb2312");
            writer.write(s);
            writer.flush();
            writer.close();
            outStream.close();
            this.mydialog = ProgressDialog.show(this, "\u4fdd\u5b58\u63a5\u6536\u533a\u6587\u5b57", "\u4fdd\u5b58\u6587\u4ef6...", D);
            new Thread() {
                @Override
                public void run() {
                    int count = 0;
                    while (count < UIActivity.xtransfing) {
                        try {
//                            AnonymousClass43.sleep(1000);
                            if (count == UIActivity.xtryconnet) {
                                UIActivity.this.mydialog.setMessage("\u5199\u5165\u6587\u4ef6...");
                            } else if (count == UIActivity.xconnected) {
                                UIActivity.this.mydialog.setMessage("\u4fdd\u5b58\u6587\u4ef6...");
                            }
                            count += UIActivity.xtryconnet;
                        } catch (Exception e) {
                            e.printStackTrace();
                            return;
                        } finally {
                            UIActivity.this.mydialog.dismiss();
                        }
                    }
                    UIActivity.this.mydialog.dismiss();
                }
            }.start();
            showTextToast("\u4fdd\u5b58\u5230:/sdcard/Com Save/" + name + ".txt");
        } catch (Exception e) {
            showTextToast("/sdcard/Com Save/" + name + ".txt \u9519\u8bef");
            Log.e("m", "file write error");
        }
    }

    public String Get_number(String st) {
        String st2 = BuildConfig.FLAVOR;
        int i = 0;
        while (i < st.length()) {
            if ('0' <= st.charAt(i) && '9' >= st.charAt(i)) {
                st2 = st2 + st.charAt(i);
            }
            i += xtryconnet;
        }
        return st2;
    }

    public void Trig_RXLED(int c) {
        RX_Count += c;
        if (RX_Count > 999999) {
            RX_Count -= 999999;
        }
        this.RX.setText("RX " + RX_Count);
        this.RX.setBackgroundColor(getResources().getColor(R.color.LED_G_ON));
        this.RX.setTextColor(getResources().getColor(R.color.Baclk));
        if (this.tmrBlink.getIsTicking()) {
            this.tmrBlink.restart();
        } else {
            this.tmrBlink.start();
        }
    }

    public void Trig_TXLED(int c) {
        TX_Count += c;
        if (TX_Count > 999999) {
            TX_Count -= 999999;
        }
        this.TX.setText("TX " + TX_Count);
        this.TX.setBackgroundColor(getResources().getColor(R.color.LED_R_ON));
        this.TX.setTextColor(getResources().getColor(R.color.Baclk));
        if (this.RtmrBlink.getIsTicking()) {
            this.RtmrBlink.restart();
        } else {
            this.RtmrBlink.start();
        }
    }

    public static String getHexString(byte[] raw, int offset, int count) throws UnsupportedEncodingException {
        StringBuffer hex = new StringBuffer();
        for (int i = offset; i < offset + count; i += xtryconnet) {
            int v = raw[i] & 255;
            hex.append(HEX_CHAR_TABLE[v >>> xend]);
            hex.append(HEX_CHAR_TABLE[v & 15]);
            hex.append(" ");
        }
        return hex.toString();
    }

    public byte[] getStringhex(String ST) {
        char[] buffer = ST.replaceAll(" ", BuildConfig.FLAVOR).toCharArray();
        byte[] Byte = new byte[(buffer.length / xconnected)];
        int index = 0;
        int bit_st = 0;
        for (int i = 0; i < buffer.length; i += xtryconnet) {
            int v = buffer[i] & 255;
            if ((v <= 47 || v >= 58) && ((v <= 64 || v >= 71) && (v <= 96 || v >= R.styleable.AppCompatTheme_buttonStyleSmall))) {
                if (v == 32) {
                    Log.v("getStringhex", "spance");
                    if (bit_st != 0) {
                        index += xtryconnet;
                        bit_st = 0;
                    }
                }
            } else if (bit_st == 0) {
                Log.v("getStringhex", "F True");
                Byte[index] = (byte) (Byte[index] | (getASCvalue(buffer[i]) * 16));
                Log.v("getStringhex", String.valueOf(Byte[index]));
                bit_st = xtryconnet;
            } else {
                Byte[index] = (byte) (Byte[index] | getASCvalue(buffer[i]));
                Log.v("getStringhex", "F false");
                Log.v("getStringhex", String.valueOf(Byte[index]));
                bit_st = 0;
                index += xtryconnet;
            }
        }
        return Byte;
    }

    public static byte getASCvalue(char in) {
        switch (in) {
            case R.styleable.AppCompatTheme_spinnerDropDownItemStyle /*48*/:
                return (byte) 0;
            case R.styleable.AppCompatTheme_homeAsUpIndicator /*49*/:
                return (byte) 1;
            case R.styleable.AppCompatTheme_actionButtonStyle /*50*/:
                return LED_SERVO_COMMAND;
            case R.styleable.AppCompatTheme_buttonBarStyle /*51*/:
                return (byte) 3;
            case R.styleable.AppCompatTheme_buttonBarButtonStyle /*52*/:
                return (byte) 4;
            case R.styleable.AppCompatTheme_selectableItemBackground /*53*/:
                return (byte) 5;
            case R.styleable.AppCompatTheme_selectableItemBackgroundBorderless /*54*/:
                return (byte) 6;
            case R.styleable.AppCompatTheme_borderlessButtonStyle /*55*/:
                return (byte) 7;
            case R.styleable.AppCompatTheme_dividerVertical /*56*/:
                return (byte) 8;
            case R.styleable.AppCompatTheme_dividerHorizontal /*57*/:
                return (byte) 9;
            case R.styleable.AppCompatTheme_imageButtonStyle /*65*/:
                return (byte) 10;
            case R.styleable.AppCompatTheme_textAppearanceSearchResultTitle /*66*/:
                return (byte) 11;
            case R.styleable.AppCompatTheme_textAppearanceSearchResultSubtitle /*67*/:
                return (byte) 12;
            case R.styleable.AppCompatTheme_textColorSearchUrl /*68*/:
                return (byte) 13;
            case R.styleable.AppCompatTheme_searchViewStyle /*69*/:
                return (byte) 14;
            case R.styleable.AppCompatTheme_listPreferredItemHeight /*70*/:
                return (byte) 15;
            case R.styleable.AppCompatTheme_textColorAlertDialogListItem /*97*/:
                return (byte) 10;
            case R.styleable.AppCompatTheme_buttonBarPositiveButtonStyle /*98*/:
                return (byte) 11;
            case R.styleable.AppCompatTheme_buttonBarNegativeButtonStyle /*99*/:
                return (byte) 12;
            case R.styleable.AppCompatTheme_buttonBarNeutralButtonStyle /*100*/:
                return (byte) 13;
            case R.styleable.AppCompatTheme_autoCompleteTextViewStyle /*101*/:
                return (byte) 14;
            case R.styleable.AppCompatTheme_buttonStyle /*102*/:
                return (byte) 15;
            default:
                return (byte) 0;
        }
    }

    private void ShowAbout() {
        startActivityForResult(new Intent(this, help.class), xtryconnet);
    }

    private void LED_ON(int index) {
        TextView opT;
        switch (index) {
            case xtryconnet /*1*/:
                opT = (TextView) findViewById(R.id.led1);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_B_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case xconnected /*2*/:
                opT = (TextView) findViewById(R.id.led2);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_G_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case xtransfing /*3*/:
                opT = (TextView) findViewById(R.id.led3);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_R_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case xend /*4*/:
                opT = (TextView) findViewById(R.id.led4);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_Y_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case idle /*5*/:
                opT = (TextView) findViewById(R.id.led21);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_B_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case TCP_READ /*6*/:
                opT = (TextView) findViewById(R.id.led22);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_G_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case TCP_CHANGE /*7*/:
                opT = (TextView) findViewById(R.id.led23);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_R_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            case R.styleable.Toolbar_contentInsetRight /*8*/:
                opT = (TextView) findViewById(R.id.led24);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_Y_ON));
                opT.setTextColor(getResources().getColor(R.color.Baclk));
                return;
            default:
                return;
        }
    }

    private void LED_OFF(int index) {
        TextView opT;
        switch (index) {
            case xtryconnet /*1*/:
                opT = (TextView) findViewById(R.id.led1);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_B_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case xconnected /*2*/:
                opT = (TextView) findViewById(R.id.led2);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_G_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case xtransfing /*3*/:
                opT = (TextView) findViewById(R.id.led3);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_R_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case xend /*4*/:
                opT = (TextView) findViewById(R.id.led4);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_Y_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case idle /*5*/:
                opT = (TextView) findViewById(R.id.led21);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_B_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case TCP_READ /*6*/:
                opT = (TextView) findViewById(R.id.led22);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_G_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case TCP_CHANGE /*7*/:
                opT = (TextView) findViewById(R.id.led23);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_R_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            case R.styleable.Toolbar_contentInsetRight /*8*/:
                opT = (TextView) findViewById(R.id.led24);
                opT.setBackgroundColor(getResources().getColor(R.color.LED_Y_OFF));
                opT.setTextColor(getResources().getColor(R.color.white_));
                return;
            default:
                return;
        }
    }

    private void setupLedController(int index, int viewId) {
        new ColorLEDController(this, index, getResources(), false).attachToView((ViewGroup) findViewById(viewId));
    }

    public void sendCommand(byte command, byte target, int value) {
        byte[] buffer = new byte[TCP_CHANGE];
        if (value > 255) {
            value = 255;
        }
        int sum = 0;
        buffer[0] = (byte) -91;
        buffer[xtryconnet] = (byte) 90;
        buffer[xconnected] = (byte) 5;
        buffer[xtransfing] = (byte) ((target + 240) + xtryconnet);
        buffer[xend] = (byte) value;
        for (int i = xconnected; i < idle; i += xtryconnet) {
            sum += buffer[i];
        }
        buffer[idle] = (byte) (sum & 255);
        buffer[TCP_READ] = (byte) -86;
        if (this.mChatService.getState() == xtransfing) {
            Trig_TXLED(buffer.length);
            this.mChatService.write(buffer);
        }
    }

    public void initial_Sation() {
        SharedPreferences config = getSharedPreferences("perference", 0);
        if (config.getString("s1_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.s1_viable = false;
        } else {
            this.s1_viable = D;
        }
        if (config.getString("s2_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.s2_viable = false;
        } else {
            this.s2_viable = D;
        }
        if (config.getString("s3_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.s3_viable = false;
        } else {
            this.s3_viable = D;
        }
        if (config.getString("LED1_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED1_viable = false;
        } else {
            this.LED1_viable = D;
        }
        if (config.getString("LED2_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED2_viable = false;
        } else {
            this.LED2_viable = D;
        }
        if (config.getString("LED3_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED3_viable = false;
        } else {
            this.LED3_viable = D;
        }
        if (config.getString("LED4_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED4_viable = false;
        } else {
            this.LED4_viable = D;
        }
        if (config.getString("LED5_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED5_viable = false;
        } else {
            this.LED5_viable = D;
        }
        if (config.getString("LED6_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED6_viable = false;
        } else {
            this.LED6_viable = D;
        }
        if (config.getString("LED7_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED7_viable = false;
        } else {
            this.LED7_viable = D;
        }
        if (config.getString("LED8_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.LED8_viable = false;
        } else {
            this.LED8_viable = D;
        }
        if (config.getString("P1_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.P1_viable = false;
        } else {
            this.P1_viable = D;
        }
        if (config.getString("P2_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.P2_viable = false;
        } else {
            this.P2_viable = D;
        }
        if (config.getString("P3_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.P3_viable = false;
        } else {
            this.P3_viable = D;
        }
        if (config.getString("P4_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.P4_viable = false;
        } else {
            this.P4_viable = D;
        }
        if (config.getString("P5_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.P5_viable = false;
        } else {
            this.P5_viable = D;
        }
        if (config.getString("P6_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.P6_viable = false;
        } else {
            this.P6_viable = D;
        }
        if (config.getString("B1_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B1_viable = false;
        } else {
            this.B1_viable = D;
        }
        if (config.getString("B2_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B2_viable = false;
        } else {
            this.B2_viable = D;
        }
        if (config.getString("B3_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B3_viable = false;
        } else {
            this.B3_viable = D;
        }
        if (config.getString("B4_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B4_viable = false;
        } else {
            this.B4_viable = D;
        }
        if (config.getString("B5_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B5_viable = false;
        } else {
            this.B5_viable = D;
        }
        if (config.getString("B6_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B6_viable = false;
        } else {
            this.B6_viable = D;
        }
        if (config.getString("B7_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B7_viable = false;
        } else {
            this.B7_viable = D;
        }
        if (config.getString("B8_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B8_viable = false;
        } else {
            this.B8_viable = D;
        }
        if (config.getString("B9_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B9_viable = false;
        } else {
            this.B9_viable = D;
        }
        if (config.getString("B10_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B10_viable = false;
        } else {
            this.B10_viable = D;
        }
        if (config.getString("B11_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B11_viable = false;
        } else {
            this.B11_viable = D;
        }
        if (config.getString("B12_viable", BuildConfig.FLAVOR).equals("flase")) {
            this.B12_viable = false;
        } else {
            this.B12_viable = D;
        }
        this.slider1_name = config.getString("slider1_name", BuildConfig.FLAVOR);
        this.slider2_name = config.getString("slider2_name", BuildConfig.FLAVOR);
        this.slider3_name = config.getString("slider3_name", BuildConfig.FLAVOR);
        this.slider1_value = config.getInt("slider1_value", 255);
        this.slider2_value = config.getInt("slider2_value", 255);
        this.slider3_value = config.getInt("slider3_value", 255);
        this.Sliderb = (ViewGroup) findViewById(R.id.sliders);
        ViewGroup g = (ViewGroup) this.Sliderb.getChildAt(0);
        this.textviewtemp = (TextView) g.getChildAt(0);
        Slider temp2 = (Slider) g.getChildAt(xtryconnet);
        this.Show_S1 = temp2;
        this.textviewtemp.setText(this.slider1_name);
        temp2.setmax((double) this.slider1_value);
        if (this.s1_viable) {
            g.setVisibility(View.VISIBLE);
        } else {
            g.setVisibility(View.GONE);
        }
        g = (ViewGroup) this.Sliderb.getChildAt(xtryconnet);
        this.textviewtemp = (TextView) g.getChildAt(0);
        temp2 = (Slider) g.getChildAt(xtryconnet);
        this.Show_S2 = temp2;
        this.textviewtemp.setText(this.slider2_name);
        temp2.setmax((double) this.slider2_value);
        if (this.s2_viable) {
            g.setVisibility(View.VISIBLE);
        } else {
            g.setVisibility(View.VISIBLE);
        }
        g = (ViewGroup) this.Sliderb.getChildAt(xconnected);
        this.textviewtemp = (TextView) g.getChildAt(0);
        temp2 = (Slider) g.getChildAt(xtryconnet);
        this.Show_S3 = temp2;
        this.textviewtemp.setText(this.slider3_name);
        temp2.setmax((double) this.slider3_value);
        if (this.s3_viable) {
            g.setVisibility(View.VISIBLE);
        } else {
            g.setVisibility(View.GONE);
        }
        this.LED1_name = config.getString("LED1_name", BuildConfig.FLAVOR);
        this.LED2_name = config.getString("LED2_name", BuildConfig.FLAVOR);
        this.LED3_name = config.getString("LED3_name", BuildConfig.FLAVOR);
        this.LED4_name = config.getString("LED4_name", BuildConfig.FLAVOR);
        this.LED5_name = config.getString("LED5_name", BuildConfig.FLAVOR);
        this.LED6_name = config.getString("LED6_name", BuildConfig.FLAVOR);
        this.LED7_name = config.getString("LED7_name", BuildConfig.FLAVOR);
        this.LED8_name = config.getString("LED8_name", BuildConfig.FLAVOR);
        TextView texttemp = (TextView) findViewById(R.id.led1);
        texttemp.setText(this.LED1_name);
        if (this.LED1_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led2);
        texttemp.setText(this.LED2_name);
        if (this.LED2_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led3);
        texttemp.setText(this.LED3_name);
        if (this.LED3_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led4);
        texttemp.setText(this.LED4_name);
        if (this.LED4_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led21);
        texttemp.setText(this.LED5_name);
        if (this.LED5_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led22);
        texttemp.setText(this.LED6_name);
        if (this.LED6_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led23);
        texttemp.setText(this.LED7_name);
        if (this.LED7_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.led24);
        texttemp.setText(this.LED8_name);
        if (this.LED8_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        this.partm1_name = config.getString("partm1_name", BuildConfig.FLAVOR);
        this.partm2_name = config.getString("partm2_name", BuildConfig.FLAVOR);
        this.partm3_name = config.getString("partm3_name", BuildConfig.FLAVOR);
        this.partm4_name = config.getString("partm4_name", BuildConfig.FLAVOR);
        this.partm5_name = config.getString("partm5_name", BuildConfig.FLAVOR);
        this.partm6_name = config.getString("partm6_name", BuildConfig.FLAVOR);
        texttemp = (TextView) findViewById(R.id.backtext1);
        texttemp.setHint(this.partm1_name);
        if (this.P1_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.backtext2);
        texttemp.setHint(this.partm2_name);
        if (this.P2_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.backtext3);
        texttemp.setHint(this.partm3_name);
        if (this.P3_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.backtext4);
        texttemp.setHint(this.partm4_name);
        if (this.P4_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.backtext5);
        texttemp.setHint(this.partm5_name);
        if (this.P5_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        texttemp = (TextView) findViewById(R.id.backtext6);
        texttemp.setHint(this.partm6_name);
        if (this.P6_viable) {
            texttemp.setVisibility(View.VISIBLE);
        } else {
            texttemp.setVisibility(View.GONE);
        }
        this.partm1_scale = config.getFloat("partm1_scale", 0.0f);
        this.partm2_scale = config.getFloat("partm2_scale", 0.0f);
        this.partm3_scale = config.getFloat("partm3_scale", 0.0f);
        this.partm4_scale = config.getFloat("partm4_scale", 0.0f);
        this.partm5_scale = config.getFloat("partm5_scale", 0.0f);
        this.partm6_scale = config.getFloat("partm6_scale", 0.0f);
        this.button1_name = config.getString("button1_name", BuildConfig.FLAVOR);
        this.button2_name = config.getString("button2_name", BuildConfig.FLAVOR);
        this.button3_name = config.getString("button3_name", BuildConfig.FLAVOR);
        this.button4_name = config.getString("button4_name", BuildConfig.FLAVOR);
        this.button5_name = config.getString("button5_name", BuildConfig.FLAVOR);
        this.button6_name = config.getString("button6_name", BuildConfig.FLAVOR);
        this.button7_name = config.getString("button7_name", BuildConfig.FLAVOR);
        this.button8_name = config.getString("button8_name", BuildConfig.FLAVOR);
        this.button9_name = config.getString("button9_name", BuildConfig.FLAVOR);
        this.button10_name = config.getString("button10_name", BuildConfig.FLAVOR);
        this.button11_name = config.getString("button11_name", BuildConfig.FLAVOR);
        this.button12_name = config.getString("button12_name", BuildConfig.FLAVOR);
        Button btntemp = (Button) findViewById(R.id.buttons1);
        btntemp.setText(this.button1_name);
        if (this.B1_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons2);
        btntemp.setText(this.button2_name);
        if (this.B2_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons3);
        btntemp.setText(this.button3_name);
        if (this.B3_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons4);
        btntemp.setText(this.button4_name);
        if (this.B4_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons5);
        btntemp.setText(this.button5_name);
        if (this.B5_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons6);
        btntemp.setText(this.button6_name);
        if (this.B6_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons7);
        btntemp.setText(this.button7_name);
        if (this.B7_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons8);
        btntemp.setText(this.button8_name);
        if (this.B8_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons9);
        btntemp.setText(this.button9_name);
        if (this.B9_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons10);
        btntemp.setText(this.button10_name);
        if (this.B10_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons11);
        btntemp.setText(this.button11_name);
        if (this.B11_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        btntemp = (Button) findViewById(R.id.buttons12);
        btntemp.setText(this.button12_name);
        if (this.B12_viable) {
            btntemp.setVisibility(View.VISIBLE);
        } else {
            btntemp.setVisibility(View.INVISIBLE);
        }
        this.button1_send = config.getString("button1_send", BuildConfig.FLAVOR);
        this.button2_send = config.getString("button2_send", BuildConfig.FLAVOR);
        this.button3_send = config.getString("button3_send", BuildConfig.FLAVOR);
        this.button4_send = config.getString("button4_send", BuildConfig.FLAVOR);
        this.button5_send = config.getString("button5_send", BuildConfig.FLAVOR);
        this.button6_send = config.getString("button6_send", BuildConfig.FLAVOR);
        this.button7_send = config.getString("button7_send", BuildConfig.FLAVOR);
        this.button8_send = config.getString("button8_send", BuildConfig.FLAVOR);
        this.button9_send = config.getString("button9_send", BuildConfig.FLAVOR);
        this.button10_send = config.getString("button10_send", BuildConfig.FLAVOR);
        this.button11_send = config.getString("button11_send", BuildConfig.FLAVOR);
        this.button12_send = config.getString("button12_send", BuildConfig.FLAVOR);
    }

    public void decode_frame(byte[] buffer, int count) {
        byte[] temp = (byte[]) buffer.clone();
        for (int i = 0; i < count; i += xtryconnet) {
            byte[] bArr;
            int i2;
            if (temp[i] == (byte) -91) {
                this.head = D;
                bArr = this.recivebuffer;
                i2 = this.wr_index;
                this.wr_index = i2 + xtryconnet;
                bArr[i2] = temp[i];
            } else if (temp[i] == (byte) 90) {
                if (this.head) {
                    this.over = false;
                    this.wr_index = 0;
                } else {
                    bArr = this.recivebuffer;
                    i2 = this.wr_index;
                    this.wr_index = i2 + xtryconnet;
                    bArr[i2] = temp[i];
                }
                this.head = false;
            } else {
                bArr = this.recivebuffer;
                i2 = this.wr_index;
                this.wr_index = i2 + xtryconnet;
                bArr[i2] = temp[i];
                this.head = false;
                if (this.wr_index == this.recivebuffer[0]) {
                    decode();
                }
            }
            if (this.wr_index == 1023) {
                this.wr_index--;
            }
            if (this.Xstate == xtryconnet) {
                if (temp[i] == (byte) 67) {
                    this.Xstate = xconnected;
                    this.Xmodemtimer.stop();
                    this.XmodemDown.setText("\u8054\u673a\u6210\u529f...\u6b63\u5728\u51c6\u5907\u6570\u636e...");
                    Log.d("XMODEM", "Transfering");
                }
            } else if (this.Xstate == xconnected) {
                if (temp[i] == (byte) 67) {
                    this.Xstate = xtransfing;
                    this.x_read_offset = 0;
                    this.rey_count = 0;
                    this.pack_num = (byte) 1;
                    Log.d("XMODEM", "Connected");
                    Xmodem_Send_Packet();
                    this.XmodemDown.setText("\u6b63\u5728\u4e0b\u8f7d\u6570\u636e...");
                    this.insendst.setVisibility(View.VISIBLE);
                    this.pb2.setVisibility(View.VISIBLE);
                    this.xmodeframec = 1;
                    this.pb2.setMax((int) this.xmodeframett);
                    this.pb2.setProgress((int) this.xmodeframec);
                    this.insendst.setText(this.xmodeframett + " / " + this.xmodeframec);
                    this.intansf.start();
                    this.tansfert = 0;
                    this.tansferuse.restart();
                }
            } else if (this.Xstate == xtransfing) {
                if (temp[i] == (byte) 6) {
                    this.xmodeframec++;
                    this.pack_num = (byte) (this.pack_num + xtryconnet);
                    Log.d("XMODEM", "ACK");
                    this.x_read_offset += this.xmodeframe;
                } else if (temp[i] == (byte) 21) {
                    Log.d("XMODEM", "NACK");
                    this.rey_count += xtryconnet;
                } else {
                    return;
                }
                this.intansf.restart();
                this.pb2.setProgress((int) this.xmodeframec);
                float tempf = ((float) this.tansfert) / 10.0f;
                if (this.rey_count == 0) {
                    this.insendst.setText(this.xmodeframett + " / " + this.xmodeframec + " \u8017\u65f6:" + tempf + "S");
                } else {
                    this.insendst.setText(this.xmodeframett + " / " + this.xmodeframec + " \u8017\u65f6:" + tempf + "S \u91cd\u4f20" + this.rey_count + "\u6b21");
                }
                if (this.rey_count > xtransfing) {
                    this.XmodemDown.setText("\u51fa\u9519\u592a\u591a \u4e2d\u6b62\u4f20\u9001");
                    Log.d("XMODEM", "ERRO Stop Transfering");
                    this.insendst.setVisibility(View.GONE);
                    this.pb2.setVisibility(View.GONE);
                    this.Xmodemopen.setEnabled(D);
                    this.XmodemSet.setEnabled(D);
                    this.Xstate = idle;
                }
                Xmodem_Send_Packet();
            } else if (this.Xstate == xend) {
                if (temp[i] == (byte) 6) {
                    this.XmodemDown.setText("\u4e0b\u8f7d\u5b8c\u6210 \u8017\u65f6:" + (((float) this.tansfert) / 10.0f) + "S");
                    Log.d("XMODEM", "Transfering End _EOT");
                    Send_Xmode_End();
                    this.Xstate = idle;
                }
                this.insendst.setVisibility(View.GONE);
                this.pb2.setVisibility(View.GONE);
                this.Xmodemopen.setEnabled(D);
                this.XmodemSet.setEnabled(D);
            } else if (this.Xstate == idle) {
            }
        }
    }

    public void decode() {
        Log.e("Decode", "\u672c\u5e27\u9700\u8981\u6821\u9a8c\u5b57\u8282" + ((this.recivebuffer[0] & 255) - 2));
        int sum = 0;
        int i = 0;
        while (i < (this.recivebuffer[0] & 255) - 2) {
            sum = (sum + (this.recivebuffer[i] & 255)) & 255;
            i += xtryconnet;
        }
        sum &= 255;
        if (sum != (this.recivebuffer[i] & 255)) {
            Log.e("Decode", "check sum err![" + sum + "] [" + (this.recivebuffer[i] & 255) + "]");
            return;
        }
        Log.e("decode", "check sum OK!");
        if (this.BL_Mode == idle) {
            switch (this.recivebuffer[xtryconnet]) {
                case joystick.COORDINATE_CARTESIAN /*0*/:
                    mdraw_osc(this.recivebuffer[xconnected] & 255);
                    break;
                case xtryconnet /*1*/:
                    mdraw_osc(((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255));
                    break;
            }
        }
        DecimalFormat df = new DecimalFormat("######0.00");
        if (this.BL_Mode == xconnected) {
            switch (this.recivebuffer[xtryconnet]) {
                case (byte) -63:
                    this.back1_text.setText(this.partm1_name + ": " + Double.toString(((double) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) * ((double) this.partm1_scale)).toString());
                    break;
                case (byte) -62:
                    this.back2_text.setText(this.partm2_name + ": " + Double.toString(((double) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) * ((double) this.partm2_scale)).toString());
                    break;
                case (byte) -61:
                    this.back3_text.setText(this.partm3_name + ": " + Double.toString(((double) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) * ((double) this.partm3_scale)).toString());
                    break;
                case (byte) -60:
                    this.back4_text.setText(this.partm4_name + ": " + Double.toString(((double) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) * ((double) this.partm4_scale)).toString());
                    break;
                case (byte) -59:
                    this.back5_text.setText(this.partm5_name + ": " + Double.toString(((double) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) * ((double) this.partm5_scale)).toString());
                    break;
                case (byte) -58:
                    this.back6_text.setText(this.partm6_name + ": " + Double.toString(((double) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) * ((double) this.partm6_scale)).toString());
                    break;
                case (byte) -31:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(xtryconnet);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(xtryconnet);
                        break;
                    }
                    break;
                case (byte) -30:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(xconnected);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(xconnected);
                        break;
                    }
                    break;
                case (byte) -29:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(xtransfing);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(xtransfing);
                        break;
                    }
                    break;
                case (byte) -28:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(xend);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(xend);
                        break;
                    }
                    break;
                case (byte) -27:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(idle);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(idle);
                        break;
                    }
                    break;
                case (byte) -26:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(TCP_READ);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(TCP_READ);
                        break;
                    }
                    break;
                case (byte) -25:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(TCP_CHANGE);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(TCP_CHANGE);
                        break;
                    }
                    break;
                case (byte) -24:
                    if (this.recivebuffer[xconnected] == (byte) 1) {
                        LED_ON(8);
                    }
                    if (this.recivebuffer[xconnected] == (byte) 0) {
                        LED_OFF(8);
                        break;
                    }
                    break;
                case (byte) -15:
                    this.Show_S1.setin_pos((double) (this.recivebuffer[xconnected] & 255));
                    break;
                case (byte) -14:
                    this.Show_S2.setin_pos((double) (this.recivebuffer[xconnected] & 255));
                    break;
                case (byte) -13:
                    this.Show_S3.setin_pos((double) (this.recivebuffer[xconnected] & 255));
                    break;
                case xtryconnet /*1*/:
                    this.Show_S1.setin_pos((double) (this.recivebuffer[xconnected] & 255));
                    this.Show_S2.setin_pos((double) (this.recivebuffer[xtransfing] & 255));
                    this.Show_S3.setin_pos((double) (this.recivebuffer[xend] & 255));
                    byte sin = (byte) 1;
                    for (i = 0; i < 8; i += xtryconnet) {
                        if (((byte) (this.recivebuffer[idle] & sin)) != (byte) 0) {
                            LED_ON(i + xtryconnet);
                        } else {
                            LED_OFF(i + xtryconnet);
                        }
                        sin = (byte) (sin << xtryconnet);
                    }
                    this.back1_text.setText(this.partm1_name + ": " + df.format(((double) (((this.recivebuffer[TCP_READ] & 255) << 8) | (this.recivebuffer[TCP_CHANGE] & 255))) * ((double) this.partm1_scale)));
                    this.back2_text.setText(this.partm1_name + ": " + df.format(((double) (((this.recivebuffer[8] & 255) << 8) | (this.recivebuffer[9] & 255))) * ((double) this.partm2_scale)));
                    this.back3_text.setText(this.partm1_name + ": " + df.format(((double) (((this.recivebuffer[10] & 255) << 8) | (this.recivebuffer[11] & 255))) * ((double) this.partm3_scale)));
                    this.back4_text.setText(this.partm1_name + ": " + df.format(((double) (((this.recivebuffer[12] & 255) << 8) | (this.recivebuffer[13] & 255))) * ((double) this.partm4_scale)));
                    this.back5_text.setText(this.partm1_name + ": " + df.format(((double) (((this.recivebuffer[14] & 255) << 8) | (this.recivebuffer[15] & 255))) * ((double) this.partm5_scale)));
                    this.back6_text.setText(this.partm1_name + ": " + df.format(((double) (((this.recivebuffer[16] & 255) << 8) | (this.recivebuffer[17] & 255))) * ((double) this.partm6_scale)));
                    break;
            }
        }
        if (this.BL_Mode == xend) {
            switch (this.recivebuffer[xtryconnet]) {
                case (byte) -73:
                    double round = (double) (((float) Math.round(10.0d * ((double) (((((float) (((this.recivebuffer[xconnected] & 255) << 8) | (this.recivebuffer[xtransfing] & 255))) / 1024.0f) * 2.56f) * 11.0f)))) / 10.0f);
                    return;
                case (byte) -52:
                    return;
                default:
                    return;
            }
        }
    }

    @Override
    public void OnOkClick(String path) {
        File file = new File(path);
        this.xmodemlastfile = path;
        this.downloadf = new File(this.xmodemlastfile);
        String temp = file.getName();
        if (temp.length() > 15) {
            temp = ".." + temp.substring(temp.length() - 13, temp.length());
        }
        this.xmodeframett = (file.length() / ((long) this.xmodeframe)) + 1;
        this.x_read_offset = 0;
        this.xmodemfile.setText(((" \u8f7d\u5165\u6587\u4ef6\u6210\u529f:" + temp + "\n") + " \u6587\u4ef6\u5927\u5c0f: " + file.length() + " \u5b57\u8282\n") + " \u9700\u8981\u4f20\u9001: " + this.xmodeframett + " \u5e27@" + this.xmodeframe + " \u5b57\u8282\u6bcf\u5e27");
        Editor editor = getSharedPreferences("perference", 0).edit();
        editor.putString("xmodemlastfile", this.xmodemlastfile);
        editor.commit();
    }

    void initial_xmodem() {
        readxmodemsetting();
        if (this.xmodemlastfile != null) {
            File file = new File(this.xmodemlastfile);
            this.downloadf = new File(this.xmodemlastfile);
            this.x_read_offset = 0;
            String temp = file.getName();
            if (file.isFile()) {
                if (temp.length() > 15) {
                    temp = ".." + temp.substring(temp.length() - 13, temp.length());
                }
                this.Xstate = idle;
                String fileif = " \u8f7d\u5165\u6587\u4ef6:" + temp + "\n";
                this.xmodeframett = (file.length() / ((long) this.xmodeframe)) + 1;
                this.xmodemfile.setText((fileif + " \u6587\u4ef6\u5927\u5c0f: " + file.length() + " \u5b57\u8282\n") + " \u9700\u8981\u4f20\u9001: " + this.xmodeframett + " \u5e27@" + this.xmodeframe + " \u5b57\u8282\u6bcf\u5e27");
            } else {
                this.xmodemfile.setText(" \u8bf7\u6253\u5f00\u8981\u4e0b\u8f7d\u7684\u6587\u4ef6");
            }
        } else {
            this.xmodemfile.setText(" \u8bf7\u6253\u5f00\u8981\u4e0b\u8f7d\u7684\u6587\u4ef6");
        }
        int j = 0;
        char[] data = new char[(this.xmodecode.length() * xconnected)];
        for (int i = 0; i < this.xmodecode.length(); i += xtryconnet) {
            int j2 = j + xtryconnet;
            data[j] = this.xmodecode.charAt(i);
            if (i % xconnected != xtryconnet || j2 == 0) {
                j = j2;
            } else {
                j = j2 + xtryconnet;
                data[j2] = ' ';
            }
        }
        this.xmodemsetting.setText(((("\u6807\u51c6XMODEM\u534f\u8bae \u6570\u636e\u5e27\u957f:" + this.xmodeframe + "\n") + "\u57fa\u672c\u8054\u673a\u5468\u671f:" + this.xmodetime + "ms ") + "\u6700\u5927\u8054\u673a\u6b21\u6570:" + this.xmoderetry + "\u6b21\n") + "\u8054\u673a\u5bc6\u7801HEX: " + new String(data, 0, j) + "\n");
    }

    void readxmodemsetting() {
        SharedPreferences config = getSharedPreferences("perference", 0);
        if (!config.getString("xmodefrist", BuildConfig.FLAVOR).equals("NO")) {
            xmodemloaddefault();
        }
        this.xmodeframe = config.getInt("xmodeframe", 0);
        this.xmoderetry = config.getInt("xmoderetry", 0);
        this.xmodetime = config.getInt("xmodetime", 0);
        this.xmodecode = config.getString("xmodecode", BuildConfig.FLAVOR);
        this.xmodemlastfile = config.getString("xmodemlastfile", BuildConfig.FLAVOR);
    }

    void xmodemloaddefault() {
        Editor editor = getSharedPreferences("perference", 0).edit();
        editor.putInt("xmodeframe", 256);
        editor.putInt("xmoderetry", 30);
        editor.putInt("xmodetime", 200);
        editor.putString("xmodecode", "4156525542");
        editor.putString("xmodefrist", "NO");
        editor.commit();
    }

    void writexmodemseting() {
        Editor editor = getSharedPreferences("perference", 0).edit();
        editor.putInt("xmodeframe", this.xmodeframe);
        editor.putInt("xmoderetry", this.xmoderetry);
        editor.putInt("xmodetime", this.xmodetime);
        editor.putString("xmodecode", this.xmodecode);
        editor.commit();
    }

    public static boolean isNumeric(String str) {
        int i = 0;
        while (i < str.length()) {
            if (!Character.isDigit(str.charAt(i)) && str.charAt(i) != '.') {
                return false;
            }
            i += xtryconnet;
        }
        return D;
    }

    public boolean isHEX(String str) {
        if (str.length() % xconnected != 0) {
            showTextToast("\u4fee\u6539\u5931\u8d25\uff0c\u8bf7\u7f16\u5199\u5b8c\u6574\u7684\u5341\u516d\u8fdb\u5236\u6570\u636e\r\n1.\u8bf7\u4e0d\u8981\u52a0\u7a7a\u683c\r\n2.\u9ad8\u4f4d\u4e3a0\u65f6\u8bf7\u628a0\u5199\u4e0a");
            return false;
        }
        int i = 0;
        while (i < str.length()) {
            if (Character.isDigit(str.charAt(i)) || str.charAt(i) == 'F' || str.charAt(i) == 'A' || str.charAt(i) == 'B' || str.charAt(i) == 'C' || str.charAt(i) == 'D' || str.charAt(i) == 'E' || str.charAt(i) == 'a' || str.charAt(i) == 'b' || str.charAt(i) == 'c' || str.charAt(i) == 'd' || str.charAt(i) == 'e' || str.charAt(i) == 'f') {
                i += xtryconnet;
            } else {
                showTextToast("\u4fee\u6539\u5931\u8d25\uff0c\u8bf7\u6b63\u786e\u7f16\u5199\u5341\u516d\u8fdb\u5236\u6570\u636e\r\n\u8f93\u5165\u6570\u5b570-9\u5b57\u6bcdA-F");
                return false;
            }
        }
        return D;
    }

    void read_xmodem_file(int len) throws IOException {
        this.fin = new FileInputStream(this.downloadf);
        this.x_ingtansf_buf = new byte[len];
        this.fin.skip((long) this.x_read_offset);
        int readl = this.fin.read(this.x_ingtansf_buf, 0, len);
        if (readl != len) {
            if (readl != -1) {
                for (int i = readl; i < len; i += xtryconnet) {
                    this.x_ingtansf_buf[i] = (byte) -1;
                }
                Log.d("XMODEM", "Read file End " + readl);
            }
            this.Xstate = xend;
        }
        this.fin.close();
    }

    void UpdataIngtansf_Buf() {
        try {
            read_xmodem_file(this.xmodeframe);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void Xmodem_Send_Packet() {
        byte[] send_data = new byte[(this.xmodeframe + idle)];
        int crc = 0;
        int i = 0 + xtryconnet;
        send_data[0] = (byte) 1;
        int i2 = i + xtryconnet;
        send_data[i] = this.pack_num;
        i = i2 + xtryconnet;
        send_data[i2] = (byte) (this.pack_num ^ -1);
        UpdataIngtansf_Buf();
        int j = 0;
        i2 = i;
        while (j < this.xmodeframe) {
            i = i2 + xtryconnet;
            send_data[i2] = this.x_ingtansf_buf[j];
            crc ^= (this.x_ingtansf_buf[j] & 255) << 8;
            for (int k = 8; k > 0; k--) {
                int t = crc << xtryconnet;
                if ((32768 & crc) != 0) {
                    t ^= 4129;
                }
                crc = t;
            }
            j += xtryconnet;
            i2 = i;
        }
        i = i2 + xtryconnet;
        send_data[i2] = (byte) (crc >> 8);
        i2 = i + xtryconnet;
        send_data[i] = (byte) crc;
        if (this.mChatService.getState() == xtransfing) {
            Trig_TXLED(send_data.length);
            this.mChatService.write(send_data);
            Log.d("XMODEM", "PackeyNum: " + this.pack_num);
        }
    }

    void Send_Xmode_End() {
        byte[] send_data = new byte[xtryconnet];
        send_data[0] = (byte) 4;
        if (this.mChatService.getState() == xtransfing) {
            Trig_TXLED(send_data.length);
            this.mChatService.write(send_data);
        }
    }

    void load_last_mode() {
        this.BL_Mode = getSharedPreferences("perference", 0).getInt("last_mod", 0);
        Mode_chagned();
    }

    void Mode_chagned() {
        SharedPreferences config = getSharedPreferences("perference", 0);
        Editor editor = config.edit();
        if (this.BL_Mode == xtryconnet) {
            this.BL_Mode = xconnected;
            editor.putInt("last_mod", xtryconnet);
        } else if (this.BL_Mode == xconnected) {
            editor.putInt("last_mod", xconnected);
            this.BL_Mode = xtransfing;
        } else if (this.BL_Mode == xtransfing) {
            editor.putInt("last_mod", xtransfing);
            this.BL_Mode = idle;
        } else if (this.BL_Mode == idle) {
            editor.putInt("last_mod", idle);
            this.BL_Mode = xtryconnet;
        } else if (this.BL_Mode == xend) {
            editor.putInt("last_mod", xend);
            this.BL_Mode = xtryconnet;
        } else {
            this.BL_Mode = xtryconnet;
        }
        editor.commit();
        if (this.BL_Mode != xend) {
            this.Updata_Timer.stop();
        } else {
            this.Updata_Timer.start();
        }
        if (this.BL_Mode == xtryconnet) {
            this.send_edit.setVisibility(View.VISIBLE);
        } else {
            this.send_edit.setVisibility(View.GONE);
        }
        if (this.BL_Mode == xtryconnet) {
            this.my_Text.setTextColor(getResources().getColor(R.color.Baclk));
            this.station.setVisibility(View.INVISIBLE);
            this.avrubd.setVisibility(View.INVISIBLE);
            this.sevo.setVisibility(View.INVISIBLE);
            this.Edit1.setVisibility(View.VISIBLE);
            this.tcp_view.setVisibility(View.INVISIBLE);
            showTextToast("\u4e32\u53e3\u52a9\u624b \u6a21\u5f0f");
        } else if (this.BL_Mode == xconnected) {
            if (!config.getString("isfrist", BuildConfig.FLAVOR).equals("NO")) {
                startActivityForResult(new Intent(this, SettingActivity.class), xtryconnet);
            }
            this.my_Text.setTextColor(Color.argb(40, 255, 255, 255));
            this.station.setVisibility(View.VISIBLE);
            this.sevo.setVisibility(View.INVISIBLE);
            this.avrubd.setVisibility(View.INVISIBLE);
            this.tcp_view.setVisibility(View.INVISIBLE);
            this.Edit1.setVisibility(View.GONE);
            showTextToast("\u76d1\u63a7\u7ad9 \u6a21\u5f0f");
        } else if (this.BL_Mode == xtransfing) {
            this.station.setVisibility(View.INVISIBLE);
            this.sevo.setVisibility(View.INVISIBLE);
            this.avrubd.setVisibility(View.VISIBLE);
            this.tcp_view.setVisibility(View.INVISIBLE);
            this.Edit1.setVisibility(View.GONE);
            initial_xmodem();
            this.my_Text.setTextColor(Color.argb(40, 255, 255, 255));
            showTextToast("\u6587\u4ef6\u4f20\u9001 \u6a21\u5f0f");
        } else if (this.BL_Mode == xend) {
            this.station.setVisibility(View.INVISIBLE);
            this.sevo.setVisibility(View.VISIBLE);
            this.avrubd.setVisibility(View.INVISIBLE);
            this.tcp_view.setVisibility(View.INVISIBLE);
            this.my_Text.setTextColor(Color.argb(40, 255, 255, 255));
            showTextToast("\u9065\u63a7\u5668 \u6a21\u5f0f");
        } else if (this.BL_Mode == idle) {
            this.station.setVisibility(View.INVISIBLE);
            this.sevo.setVisibility(View.INVISIBLE);
            this.avrubd.setVisibility(View.INVISIBLE);
            this.tcp_view.setVisibility(View.VISIBLE);
            this.my_Text.setTextColor(Color.argb(40, 255, 255, 255));
            showTextToast("TCPIP\u900f\u4f20 \u6a21\u5f0f");
        }
    }

    private void nameSeting(String Title, String name) {
        View addView = LayoutInflater.from(this).inflate(R.layout.add_editnam, null);
        final DialogWrapper wrapper = new DialogWrapper(addView);
        wrapper.setnametext(name);
        new AlertDialog.Builder(this).setTitle(Title).setView(addView).setPositiveButton("\u786e\u5b9a", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                UIActivity.this.csv_fname = wrapper.getTitleField().getText().toString();
                UIActivity.this.filent.setText("\u6587\u4ef6\u540d:" + UIActivity.this.csv_fname + ".CSV");
                UIActivity.this.write_head();
            }
        }).setNegativeButton("\u53d6\u6d88", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        }).show();
    }

    public void write_head() {
        Editor editor = getSharedPreferences("perference", 0).edit();
        editor.putString("lastfile_name", this.csv_fname);
        editor.commit();
    }

    public void Write_CSV_File(byte[] buffer, int len, String fname) {
        File destDir = new File("/sdcard/Com Save");
        byte[] data = new byte[len];
        for (int i = 0; i < len; i += xtryconnet) {
            data[i] = buffer[i];
        }
        if (!destDir.exists()) {
            destDir.mkdirs();
        }
        try {
            FileOutputStream outStream = new FileOutputStream("/sdcard/Com Save/" + fname + ".txt", D);
            File destDir2 = new File("/sdcard/Com Save/" + fname + ".txt");
            try {
                BufferedOutputStream writer = new BufferedOutputStream(outStream);
                writer.write(data);
                writer.flush();
                writer.close();
                outStream.close();
                this.filent.setText("\u6587\u4ef6\u540d:/sdcard/Com Save/" + fname + ".txt\r\n\u5df2\u5199\u5165 " + destDir2.length() + " \u5b57\u8282");
                destDir = destDir2;
            } catch (Exception e) {
                destDir = destDir2;
                Log.e("m", "file write error");
            }
        } catch (Exception e2) {
            Log.e("m", "file write error");
        }
    }

    void mdraw_osc(int ndata) {
        int length = this.series.getItemCount();
        this.addX = 0;
        this.addY = ndata;
        this.mDataset.removeSeries(this.series);
        if (length > 1000) {
            length = 1000;
        }
        for (int i = 0; i < length; i += xtryconnet) {
            this.xv[i] = ((int) this.series.getX(i)) + xtryconnet;
            this.yv[i] = (int) this.series.getY(i);
        }
        this.series.clear();
        this.series.add((double) this.addX, (double) this.addY);
        for (int k = 0; k < length; k += xtryconnet) {
            this.series.add((double) this.xv[k], (double) this.yv[k]);
        }
        this.mDataset.addSeries(0, this.series);
        this.chart.invalidate();
    }

    void initial_osc() {
        LinearLayout layout = (LinearLayout) findViewById(R.id.oscdis);
        this.series = new XYSeries("DATA");
        this.mDataset = new XYMultipleSeriesDataset();
        this.mDataset.clear();
        this.mDataset.addSeries(0, this.series);
        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(-16711936);
        r.setLineWidth(3.0f);
        XYSeriesRenderer r2 = new XYSeriesRenderer();
        r2.setColor(-65536);
        r2.setLineWidth(3.0f);
        this.renderer = buildRenderer(-16711936, PointStyle.CIRCLE, D);
        setChartSettings(this.renderer, "X", "Y", 0.0d, 500.0d, 0.0d, 260.0d, -1, -1);
        this.renderer.removeAllRenderers();
        this.renderer.addSeriesRenderer(0, r);
        this.chart = ChartFactory.getLineChartView(this.context, this.mDataset, this.renderer);
        layout.addView(this.chart, new LayoutParams(-1, -1));
        this.chart.invalidate();
    }

    protected XYMultipleSeriesRenderer buildRenderer(int color, PointStyle style, boolean fill) {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(color);
        r.setPointStyle(style);
        r.setFillPoints(fill);
        r.setLineWidth(2.0f);
        renderer.addSeriesRenderer(r);
        return renderer;
    }

    protected void setChartSettings(XYMultipleSeriesRenderer renderer, String xTitle, String yTitle, double xMin, double xMax, double yMin, double yMax, int axesColor, int labelsColor) {
        renderer.setChartTitle(this.title);
        renderer.setChartTitleTextSize(24.0f);
        renderer.setXTitle(xTitle);
        renderer.setYTitle(yTitle);
        renderer.setXAxisMin(xMin);
        renderer.setXAxisMax(xMax);
        renderer.setYAxisMin(yMin);
        renderer.setYAxisMax(yMax);
        renderer.setAxesColor(axesColor);
        renderer.setLabelsColor(labelsColor);
        renderer.setLabelsTextSize(16.0f);
        renderer.setShowGrid(D);
        renderer.setGridColor(-7829368);
        renderer.setXLabels(20);
        renderer.setYLabels(20);
        renderer.setAxisTitleTextSize(20.0f);
        renderer.setXTitle(" ");
        renderer.setYTitle("\u6e29\u5ea6[C]");
        renderer.setYLabelsAlign(Align.LEFT);
        renderer.setPointSize(1.0f);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouch(final View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN && event.getPointerCount() == 1) {

//             newBean = new NewBean(new ArrayList<Encoder>(), 5, "W");
//          String  message = "&" + mGson.toJson(newBean) + "&";
//            sendMessage(message);
            if (v.getId() == R.id.ok) {
                Log.d("OnOneActivity", "我停止了1222");
                updateAddOrSubtract();
            }

        } else if (event.getAction() == MotionEvent.ACTION_UP && event.getPointerCount() == 1) {
            if (v.getId() == R.id.ok) {

                //手指抬起时停止发送
                stopAddOrSubtract();
            }
        }

//        else if (event.getAction() == MotionEvent.ACTION_UP && event.getPointerCount() == 1) {
//
//            updateAddOrSubtract();
//        }

        return true;
    }


    ScheduledThreadPoolExecutor exec;

    private void updateAddOrSubtract() {
        exec = new ScheduledThreadPoolExecutor(1);
        exec.scheduleAtFixedRate(new Runnable() {//每隔一段时间就触发异常
            @Override
            public void run() {
//                newBean = new NewBean(new ArrayList<>(), 5, "W");
                sendMessage( "w");
                Log.d(TAG, "22222222222222222222");
            }


        }, 0, 41, TimeUnit.MILLISECONDS);

//        try {
//            if (!exec.awaitTermination(3000, TimeUnit.MILLISECONDS)) {
//                // 超时的时候向线程池中所有的线程发出中断(interrupted)。
//                exec.shutdownNow();
//                Log.d(TAG, "我停止了");
//            }
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
    }
    // 向学生传达“XX分之内解答不完的问题全部带回去作为课后作业！”后老师等待学生答题
    // (所有的任务都结束的时候，返回TRUE)


    private void stopAddOrSubtract() {
        Log.d(TAG, "我停11111111止了");
        if (exec != null) {
            exec.shutdownNow();
            exec = null;
        }
    }
}

